/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.plattysoft.leonids.examples.slice;

import com.plattysoft.leonids.ParticleSystem;
import com.plattysoft.leonids.examples.ResourceTable;
import com.plattysoft.leonids.examples.utils.ResUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.element.ShapeElement;

public class EmiterBackgroundSimpleExampleAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private ComponentContainer mRootId;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer rootLayout = (ComponentContainer) LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_main_emit_bg, null, false);
        mRootId = (ComponentContainer) rootLayout.findComponentById(ResourceTable.Id_backgd);
        ShapeElement background_color_element = new ShapeElement();
        background_color_element.setShape(ShapeElement.RECTANGLE);
        background_color_element.setRgbColor(new RgbColor(0, 0, 0));
        background_color_element.setBounds(0, 0, mRootId.getRight(), mRootId.getBottom());
        mRootId.setBackground(background_color_element);
        rootLayout.findComponentById(ResourceTable.Id_buttonplay).setClickedListener(this);
        super.setUIContent(rootLayout);
    }

    @Override
    public void onClick(Component component) {
        new ParticleSystem(mRootId, 20, ResUtil.getPixelMapElementByResId(getContext(), ResourceTable.Media_star_pink), 1000)
                .setSpeedRange(0.1f, 0.25f)
                .emit(component, 40);
    }
}
